<?php
function invalid() {
    //header('HTTP/1.0 404 Not Found');
    echo "<h1>404 Not Found</h1>";
    echo "The page that you have requested could not be found.";
    exit();
}

if(empty($_GET['page'])) {
    //Default page
    $page = "home";
}
else {
    $page = $_GET['page'];
}

if(empty($_GET['action'])) { 
    $action = 'index';
} 
else {
    $action = $_GET['action'];
}

$file =  $page.'_controller.php';
if(file_exists($file)) {
    include $file;
    $classname = ucfirst($page).'_Controller';
    $class = new $classname();
    if($class)
        if(method_exists($class,$action)) {
            echo $class->$action();
        }
        else {
            invalid();
        }
}
else {
    invalid();
}
?>
